package com.baizhi.exception;

import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Component
public class GlobalException implements HandlerExceptionResolver {
    @Override
    public ModelAndView resolveException(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, Exception e) {
        /*打印异常堆栈信息*/
        e.printStackTrace();

        //定义ModelAndView
        ModelAndView mav = new ModelAndView();
        //跳转到错误页
        mav.setViewName("error");

        return mav;
    }
}
